<?php
	function habilitation()
	{
		$hab = array(
			1,
			2
		);
		
		if (in_array(get_s('bo_user_role'), $hab))
			return true;
		return false;
	}
	
	function view($table, $id)
	{
		if (habilitation())
		{
			$retour = array();
			$champs = champs();
			$champaff = '';
			foreach ($champs as $champ)
				$champaff .= $champ['id'] . ', ';
			$champaff = substr($champaff, 0, -2);
			$gp_db = GP_db::getInstance(BDD_DSN, BDD_UTILISATEUR, BDD_MOT_DE_PASSE);
			$sql = "SELECT $champaff FROM $table WHERE id = $id";
			$tab = $gp_db -> fetchArray_one($sql);
			
			foreach ($tab as $cle => $valeur)
			{
				$type = $champs[$cle]["type"];
				if ($type == 'input')
					$retour[$champs[$cle]["Affichage"]] = sl($valeur);
				else if ($type == 'password')
					$retour[$champs[$cle]["Affichage"]] = '***';
				else if ($type == 'select')
				{
					$type_select = $champs[$cle]["typeselect"];
					
					if ($type_select == 'vocabulaire')
					{
						$vocabulaire = $champs[$cle]["data"];
						$tabvoc = explode(';', $vocabulaire);
						
						foreach ($tabvoc as $seg)
						{
							list($seg_c, $seg_v) = explode('%%', $seg, 2);
							if ($seg_c == $valeur)
							{
								$retour[$champs[$cle]["Affichage"]] = sl($seg_v);
								break;
							}
						}
					}
					
					else if ($type_select == 'sql')
					{
						$requete = $champs[$cle]["data"];
						$tagseg = $gp_db -> fetchRow($requete);
						foreach ($tagseg as $ligne)
						{
							if ($ligne[0] == $valeur)
							{
								$retour[$champs[$cle]["Affichage"]] = sl($ligne[1]);
								break;
							}
						}
					}
				}
			}
			
			return $retour;
		}
		return false;
	}
	
	function champs()
	{
		$retour = array();
		
		$retour['name']['id'] = 'name';
		$retour['name']['Affichage'] = 'Nom';
		$retour['name']['max'] = 60;
		$retour['name']['type'] = 'input';
		$retour['name']['obligatoire'] = true;

		return $retour;
	}
	
	
	$this -> setvar('titre', 'Afficher une ligne de produits');
	$this -> setvar('retour_url', rw('contenus'));
	$this -> setvar('habilitation', habilitation());
	$this -> setvar('tableau', view($this -> table, $this -> id));
?>